<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input
        type="text" 
        placeholder="enter the name you search"
        v-model="keyword"
      />&nbsp;
      <button @click="handelSearch">Search</button>
    </div>
  </section>
</template>

<script>
import axios from 'axios'
export default {
  name: 'SearchView',
  data() {
    return {
      keyword: '',
    }
  },
  methods: {
    handelSearch() {
      this.$bus.$emit('getList', {
        isFirst: false,
        isLoading: true,
      })
      axios.get(`https://api.github.com/search/users?q=${this.keyword}`).then(response => {
        console.log('获取数据成功', response)
        this.$bus.$emit('getList', {
          isLoading: false,
          list: response.data.items,
        })
      }).catch((error) => {
        console.log('获取数据失败', error)
        this.$bus.$emit('getList', {
          isLoading: false,
          list: [],
          msg: error.message
        })
      })
    }
  }
}
</script>

<style lang="less" scoped>

</style>
